package com.woniuxy.config.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 马宇航
 * @Description: 延迟交换机
 * @DateTime: 25/10/28/星期二 15:39
 * @Component: 成都蜗牛学苑
 **/
@Configuration
public class DelayExchangeConfig {
    @Bean
    public Queue delayQueue(){
        return new Queue("delayQueue");
    }
    @Bean
    public CustomExchange delayExchange(){
        //下面的配置根据官方文档来的，如果大家项目要使用mq来发email
        Map<String, Object> args = new HashMap<String, Object>();
        //相当于这个延迟交换机 是使用的直连交换机，其他广播，header，topic都能用
        args.put("x-delayed-type", "direct");
        return new CustomExchange("delayExchange", "x-delayed-message", true, false, args);
    }
    @Bean
    public Binding delayBinding(){
        return BindingBuilder.bind(delayQueue()).to(delayExchange()).with("delay").noargs();
    }
}
